//
//  HeaderOfShop.m
//  PetAPP
//
//  Created by apple on 16/2/14.
//  Copyright © 2016年 Yuming. All rights reserved.
//

#import "HeaderOfShop.h"
#import "NetworkingHandle.h"
#import <YYWebImage.h>
#import "CustomForHeaderOfShop.h"

@interface HeaderOfShop ()

@property (nonatomic, retain) NSMutableDictionary *picURL;

@property (nonatomic, retain) UIImageView *imageViewOfPic;


@end

@implementation HeaderOfShop

- (void)dealloc {

    [_picURL release];
    [_imageViewOfPic release];
    [super dealloc];

}

- (instancetype)initWithFrame:(CGRect)frame {

    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViewsWithFrame:(CGRect){.size = frame.size}];
        [self handleData];
    }
    return self;
}

- (void)handleData {
    [NetworkingHandle handleWorkData:@"http://api.leepet.com/?m=EC&a=banner" AndBody:[NSString stringWithFormat:@"uid=%@", [[NSUserDefaults standardUserDefaults] stringForKey:@"uid"]] value:@{@"Content-Type" : @"application/x-www-form-urlencoded"} handleBlock:^(id result) {
        NSArray *tempArr = [result objectForKey:@"data"];
        
        
        self.picURL = [NSMutableDictionary dictionaryWithDictionary:tempArr[0]];
//        self.imageViewOfPic.yy_imageURL = [NSURL URLWithString:[self.picURL objectForKey:@"coverpath"]];
        [self.imageViewOfPic yy_setImageWithURL:[NSURL URLWithString:[self.picURL objectForKey:@"coverpath"]] options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation];

    }];
    
    

}

- (void)createSubViewsWithFrame:(CGRect)frame {
    /** 创建上面的大广告 */
    self.imageViewOfPic = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 150)];
    [self addSubview:_imageViewOfPic];
    [_imageViewOfPic release];
    
    /** 创建三个图标 */
    UIImageView *threePicView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 150, frame.size.width, 100)];
    [self addSubview:threePicView];
    [threePicView release];
    threePicView.image = [UIImage imageNamed:@"taobaozutu"];
    threePicView.userInteractionEnabled = YES;
    
    for (int i = 0 ; i < 3; i++) {
        CustomForHeaderOfShop *view = [[CustomForHeaderOfShop alloc] initWithFrame:CGRectMake(i * (frame.size.width / 3), 0, frame.size.width / 3, 100)];
        [threePicView addSubview:view];
        [view release];
        view.tag = i + 10;
        
    }
    
    /** 创建特卖的线 */
    UIView *viewOfSale = [[UIView alloc] initWithFrame:CGRectMake(0, 250, frame.size.width, 35)];
    [self addSubview:viewOfSale];
    [viewOfSale release];
    viewOfSale.backgroundColor = [UIColor colorWithRed:0.9625 green:0.9625 blue:0.9625 alpha:1.0];

    
    
    UIView *viewOfGrayLine = [[UIView alloc] initWithFrame:CGRectMake(0, 17, frame.size.width, 1)];
    [viewOfSale addSubview:viewOfGrayLine];
    [viewOfGrayLine release];
    
    viewOfGrayLine.layer.borderWidth = 1;
    viewOfGrayLine.layer.borderColor = [UIColor grayColor].CGColor;
    
    
    
    UILabel *labelOfSale = [[UILabel alloc] initWithFrame:CGRectMake(viewOfSale.center.x - 50, 0, 100, 35)];
    [viewOfSale addSubview:labelOfSale];
    [labelOfSale release];
    
    labelOfSale.backgroundColor = [UIColor colorWithRed:0.9625 green:0.9625 blue:0.9625 alpha:1.0];
    
    labelOfSale.textColor = [UIColor grayColor];
    labelOfSale.text = @"特卖专场";
    labelOfSale.textAlignment = NSTextAlignmentCenter;
    


}


@end
